package jiang.app.service;

import java.util.List;

import jiang.app.dao.IPermissionDao;
import jiang.app.dao.IRoleDao;
import jiang.app.dao.IUserDao;
import jiang.app.entity.Role;
import jiang.app.entity.User;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
public class UserService {
	@Autowired
	IUserDao userDao;
	@Autowired
	IRoleDao roleDao;
	@Autowired
	IPermissionDao permissionDao;
	
	@Transactional(readOnly = true)
	public User findUserByUsernameAndPassword(User u){
		User user = userDao.selectUserByUsernameAndPassword(u);
		return user;
	}
	
	@Transactional(readOnly = true)
	public User findUserById(long id){
		User user = userDao.selectUserById(id);
		return user;
	}
	
	@Transactional
	public List<Role> findRolesByUserId(long id){
		return roleDao.selectRolesByUserId(id);
	}
}
